//
//  DataTools.m
//  FrameTest
//
//  Created by Tiger on 11-11-1.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "DataTools.h"
#import <commoncrypto/CommonDigest.h>

@implementation DataTools

- (void)dealloc{
	[super dealloc];
}

+ (NSString *)MD5:(NSString *)str { 
    const char *cStr = [str UTF8String];
	unsigned char result[16];
	CC_MD5( cStr, strlen(cStr), result );
	return [NSString stringWithFormat:
			@"%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
			result[0], result[1], result[2], result[3], 
			result[4], result[5], result[6], result[7],
			result[8], result[9], result[10], result[11],
			result[12], result[13], result[14], result[15]
			];
}

+ (NSString*)dateFromNumber:(NSNumber *)number {
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
	[formatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"] autorelease]];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm"];
	
	[formatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"H"]];
    NSTimeInterval atime = [number longLongValue];///1000;
    NSDate* date = [NSDate dateWithTimeIntervalSince1970:atime];
    NSString* dateStr = [formatter stringFromDate:date];
    [formatter release];
    return dateStr;
}

+ (NSString *)stringOfDate:(NSDate *)date formatString:(NSString *)str {
	NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
	[formatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"] autorelease]];
    [formatter setDateFormat:str];
	[formatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"H"]];
	NSString* dateStr = [formatter stringFromDate:date];
    [formatter release];
	return dateStr;
}

@end
